/**@FILE:ToyAction.java
 * @AUTHOR:qingsheng.zheng
 * @DATE:2015-2-1 上午11:39:59*/
package com.xf.toy.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xf.pub.exception.ServiceException;
import com.xf.pub.logger.LoggerUtil;
import com.xf.toy.bean.Toy;
import com.xf.toy.dao.page.Pagination;
import com.xf.toy.service.ToyService;
import com.xf.toy.web.common.BaseAction;

import framework.Page;

/*******************************************
 * @COMPANY:alibaba
 * @CLASS:ToyAction
 * @DESCRIPTION:
 * @AUTHOR:qingsheng.zheng
 * @VERSION:v1.0
 * @DATE:2015-2-1 上午11:39:59
 *******************************************/
@Controller
@RequestMapping(value = "/toy/toyinfo")
public class ToyAction extends BaseAction {
	@Resource(name = "toyService")
	private ToyService toyService;
	private Long userid;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public void queryList(
			@RequestParam(required = false, defaultValue = "") String theme,
			@RequestParam(required = false, defaultValue = "") String age,
			@RequestParam(required = false, defaultValue = Page.DEF_PAGE_NO) Integer pageNo,
			@RequestParam(required = false, defaultValue = Page.DEF_PAGE_SIZE) Integer pageSize,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			Toy toy = new Toy();
			toy.setToyTheme(theme);
			toy.setToyAge(age);
			Pagination page = new Pagination();
			page.setPageSize(pageSize);
			page.setCurrentPage(pageNo);
			userid=super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method","toy/info/list","userid",userid+""));
			List<Toy> toyList = toyService.selectToysPagination(toy, page);
			response(resp, toyList,page);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public void detail(
			@RequestParam(required = false, defaultValue = "") String toycode,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			Toy toy = toyService.selectOneByCode(toycode);
			userid=super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method","toy/info/detail","userid",userid+""));
			response(resp, toy);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}
	@RequestMapping(value = "/dictage", method = RequestMethod.GET)
	public void getDistinctAge(
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			List<String> value = toyService.getDistinctAge();
			userid=super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method","toy/info/dictage","userid",userid+""));
			response(resp, value);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}
	
	@RequestMapping(value = "/dicttheme", method = RequestMethod.GET)
	public void getDistinctTheme(
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			List<String> value = toyService.getDistinctTheme();
			userid=super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method","toy/info/dicttheme","userid",userid+""));
			response(resp, value);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}
}
